package com.project.controller;
import com.project.bean.UserBean;
import com.project.service.IUserService2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

@RestController
@RequestMapping("user")
public class UserController {
    @Autowired
    private IUserService2 service;

    @RequestMapping("login")
    public String login(String acc, String pwd, HttpServletRequest request){
        UserBean user = service.login(acc, pwd);
        if(user != null){
            request.getSession().setAttribute("loginUser",user);
            return "ok";
        }
        return "no";
    }
    @RequestMapping("add")
    public  String  zc(UserBean user ){

        service.add(user);

        return "ok";
    }

    @RequestMapping("getUserAcc")
    public UserBean getUserAccount(HttpServletRequest request){
        UserBean userBean = (UserBean)request.getSession().getAttribute("loginUser");
        System.out.println(userBean);
        return userBean;
    }
}
